package com.example.PolimiAssistant.common;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.Wsdl2Code.WebServices.PolimiAssistant.CourseInfo;
import com.example.PolimiAssistant.R;

import java.util.List;

/**
 * Created by Vlado on 29.06.2014.
 */
public class ExamScheduleAdapter extends ArrayAdapter<CourseInfo> {
    int resource;
    String response;
    Context context;

    public ExamScheduleAdapter(Context context, int resource, List<CourseInfo> items) {
        super(context, resource, items);
        this.resource=resource;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LinearLayout examsheduleView;
        CourseInfo info = getItem(position);

        //Inflate the view
        if(convertView==null)
        {
            examsheduleView = new LinearLayout(getContext());
            String inflater = Context.LAYOUT_INFLATER_SERVICE;
            LayoutInflater vi;
            vi = (LayoutInflater)getContext().getSystemService(inflater);
            vi.inflate(resource, examsheduleView, true);
        }
        else
        {
            examsheduleView = (LinearLayout) convertView;
        }

        TextView exam_schedule_course_name =(TextView)examsheduleView.findViewById(R.id.exam_schedule_course_name);
        TextView exam_schedule_semestar_name =(TextView)examsheduleView.findViewById(R.id.exam_schedule_semestar_name);

        exam_schedule_course_name.setText(info.name);
        exam_schedule_semestar_name.setText(info.semestar_name);

        return examsheduleView;
    }
}
